﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace SUMO.MediaBrowser.Controls.Adorners
{
    public class AdornedObject : IAdornedObject
    {
        RotateTransform _rotate;
        FrameworkElement _adornedElement;

        public AdornedObject(FrameworkElement element, double angle)
            : this(element)
        {
            Angle = angle;
        }

        public AdornedObject(FrameworkElement element, double x, double y, double angle) : this(element)
        {
            X = x;
            Y = y;
            Angle = angle;
        }

        public AdornedObject(FrameworkElement element)
        {
            _adornedElement = element;
            _adornedElement.RenderTransformOrigin = new Point(0.5, 0.5);
            _rotate = new RotateTransform();
            _adornedElement.RenderTransform = _rotate;
        }

        #region IAdornedObject Members

        public double Angle
        {
            get { return _rotate.Angle; }
            set { _rotate.Angle = value; }
        }

        public double X
        {
            get { return Canvas.GetLeft(_adornedElement); }
            set { Canvas.SetLeft(_adornedElement, value); }
        }

        public double Y
        {
            get { return Canvas.GetTop(_adornedElement); }
            set { Canvas.SetTop(_adornedElement, value); }
        }

        public double ObjectWidth
        {
            get { return _adornedElement.Width; }
            set { _adornedElement.Width = value; }
        }

        public double ObjectHeight
        {
            get { return _adornedElement.Height; }
            set { _adornedElement.Height = value; }
        }

        #endregion
    }
}
